package com.kuanter.kuanterauto.activity;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.baseui.BaseActivity_NoBar;
import com.kuanter.kuanterauto.constants.HttpConfigAPI;
import com.kuanter.kuanterauto.constants.MainConstants;
import com.kuanter.kuanterauto.entity.DJDTO;
import com.kuanter.kuanterauto.net.HttpTask;
import com.kuanter.kuanterauto.utils.DataLoader;
import com.kuanter.kuanterauto.utils.JsonParser;
import com.umeng.analytics.MobclickAgent;

/**
 * 代驾
 * @author kuanter
 *
 */
public class HelpDriveActivity extends BaseActivity_NoBar {
	RelativeLayout help_top;
	String helpDrive = "代驾服务";
	TextView title;
//	ImageView banner;
	TextView banner_tv;
	
	TextView djdh;
	
	DJDTO dj;
	
	Handler dj_handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			finishProgress();
			if(msg.what == HttpTask.RESULT_OK) {
				String json = (String) msg.obj;
				dj = JsonParser.getDJ(json);
				if(dj.getPhoneNumber() != null && !dj.getPhoneNumber().equals("")) {
					djdh.setText("代驾电话:  " + dj.getPhoneNumber());
				} else {
					djdh.setText("代驾电话: 暂无");
				}
				
				if(dj.getNote() != null) {
					banner_tv.setText(dj.getNote());
				}
			} else {
				showToast("加载数据失败");
			}
			super.handleMessage(msg);
		}
		
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.kuanter_helpdrive);
		showProgress("正在加载数据...");
		help_top = (RelativeLayout) findViewById(R.id.help_top);
		TextView title = (TextView) help_top.findViewById(R.id.top_middle);
		title.setText(helpDrive);
		
		djdh = (TextView) findViewById(R.id.djdh);
//		djdh.setText("代驾电话:  400-6666-377");
		djdh.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				if(dj != null && dj.getPhoneNumber() != null && !dj.getPhoneNumber().equals("暂无")) {
					new AlertDialog.Builder(HelpDriveActivity.this)
					.setMessage("是否拨打电话: " + dj.getPhoneNumber())
					.setPositiveButton("确认", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							Intent intent_call = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + dj.getPhoneNumber()));
							startActivity(intent_call);
						}
					})
					.setNegativeButton("取消", null)
					.create().show();
				} else {
					
				}
			}
		});
		
		LinearLayout home_chose_City = (LinearLayout) help_top.findViewById(R.id.home_chose_City);
		home_chose_City.setVisibility(View.GONE);
		
		DataLoader loader = new DataLoader(HelpDriveActivity.this);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
//		NameValuePair cityID = new BasicNameValuePair("cityCode",SharePrefenceUtil.getCityID(HelpDriveActivity.this));
//		params.add(cityID);
		loader.DisplayData(MainConstants.HOST_test + HttpConfigAPI.findDesignatedDrivingInfo, params, dj_handler, "", false);
		
//		banner = (ImageView) findViewById(R.id.banner);  //816
		
		banner_tv = (TextView) findViewById(R.id.banner_tv);
		/*if(screenWidth == 480) {
			DownLoadImage down = new DownLoadImage(screenWidth + 80,screenHeight * 3 / 4,banner);
//			down.execute(MerchantTurnActivity1.img);
		} else {
			DownLoadImage down = new DownLoadImage(screenWidth + 96,screenHeight * 3 / 4,banner);
//			down.execute(MerchantTurnActivity1.img);
		}*/
		
		
	}
	
	
	@Override
	protected void onPause() {
		MobclickAgent.onPause(this);
		super.onPause();
	}

	@Override
	protected void onResume() {
		MobclickAgent.onResume(this);
		super.onResume();
	}



	public void exit(View view) {
		finish();
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		
	}
		
}
